<%String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="<%=path%>/media/js/jquery.1.9.js" ></script>
    <title>简易设备资产管理系统</title>
   
  </head>
  <body>
  <div style="margin-left: auto;margin-right: auto;">
    <h2>简易设备资产管理系统</h2>
    <br>
    <h5> 欢迎【${user.realName}】【<c:if test="${user.type == 1}">普通用户</c:if>
      <c:if test="${user.type == 0}">管理员</c:if>】使用设备资产管理系统
      <a href="<%=path%>/doLogout.html" ><button>退出</button></a></h5>

    <br>
    <div style="border:1px solid #000;width: 640px;background-color:#eee;" >
      <br>
      名称：<input type="text" name="name" id="name" />
      编码：<input type="text" name="code" id="code" />
      价格：<input type="number" name="price" id="price" style="width: 76px;" />
      <br><br>
      描述：<textarea style="width: 532px;" id="description"></textarea>
      <br><br>
      领用人:<select style="width: 172px;" id="userId" >
              <c:forEach items="${users}" var="users">
                 <option value="${users.id}" >${users.realName}</option>
              </c:forEach>
            </select>
      存放地点：<input type="text" name="place" id="place" />
      <button onclick="addEquipment()" >添加设备</button>

      <br><br>
    </div>



    <br>


    <table border="1px" >
       <tr>
         <th>序号</th>
         <th>资产编码</th>
         <th>名称</th>
         <th>价格</th>
         <th>存放地点</th>
         <th>领用人</th>
         <th>领用时间</th>
       </tr>
      <c:forEach varStatus="index" var="equipment" items="${equipments}">
        <tr>
          <th>${index.count}</th>
          <th>${equipment.code}</th>
          <th>${equipment.name}</th>
          <th>${equipment.price}</th>
          <th>${equipment.place}</th>
          <th>${equipment.userName}</th>
          <th>${equipment.addTime}</th>
        </tr>
      </c:forEach>

    </table>


  </div>
  </body>
<script>
    function addEquipment() {

      $.ajax({
        url : "addEquipment.html",
        type : 'post',
        dataType : 'json',
        data : {
          name : $("#name").val(),
          code : $("#code").val(),
          price : $("#price").val(),
          description : $("#description").val(),
          userId : $("#userId").val(),
          place : $("#place").val()
        },
        success : function(rd) {
          if (rd) alert("添加成功");
          window.location.reload();
        }
      })
    }

</script>
</html>